using RAG.Domain.Repositories;
using RAG.Domain.Services;

namespace RAG.Infrastructure.Services;

public class VectorSearchService : IVectorSearchService
{
    private readonly IKnowledgeBaseRepository _knowledgeBaseRepository;

    public VectorSearchService(IKnowledgeBaseRepository knowledgeBaseRepository)
    {
        _knowledgeBaseRepository = knowledgeBaseRepository;
    }

    public async Task<List<(Guid ChunkId, double Similarity)>> SearchSimilarChunksAsync(
        float[] queryEmbedding,
        int topK = 5,
        double threshold = 0.7)
    {
        var knowledgeEntries = await _knowledgeBaseRepository.SearchSimilarAsync(queryEmbedding, topK, threshold);

        // 转换为原有格式以保持接口兼容性
        return knowledgeEntries.Select(kb => (kb.ChunkId, 1.0)).ToList(); // 临时使用1.0作为相似度
    }
}
